import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:saas_order_meal/model/week_food_model.dart';
import 'package:saas_order_meal/net/net_response/elder_bind_info.dart';
import 'package:saas_order_meal/net/net_response/elser_week_bind_info.dart';
import '../model/combo_model.dart';
import '../net/net_response/elder_month_record.dart';

var orderFoodShowPrice = true;

class ElderMonthRecordViewModel
    extends BaseListViewModel<ElderMonthRecordList> {
  final String oldId;

  var model = WeekFoodModel();
  var comboModel = ComboModel();

  var packageInfo = "";

  ElderMonthRecordViewModel(BuildContext context, this.oldId) : super(context);

  ElderMonthRecord? oldInfo;

  @override
  Future<List<ElderMonthRecordList>> requestListData() async {
    var data = await model.getElderMonth(elderHumanId: oldId, showDay: 21);
    getCanShowPrice();
    oldInfo = data;
    packageInfo = data.packageConfName ?? "";
    return data.list ?? <ElderMonthRecordList>[];
  }

  @override
  void onCreated() {
    super.onCreated();
    requestRefresh();
  }

  @override
  void receiveMessage(SendMessageEvent event) {
    super.receiveMessage(event);
  }

  Future<ElderWeekBindInfo?> getElderBindInfo(String date) async {
    try {
      var data = await model.getElderWeekBindInfo(oldId, date);
      hideDialog();
      return data;
    } catch (e) {
      hideDialog();
      showToast(e.toNetError());
      return null;
    }
  }

  ///能否显示点餐价格
  Future<void> getCanShowPrice() async {
    try {
      var data = await comboModel.getComboData(38391);
      if (data.isNotEmpty) {
        orderFoodShowPrice = data.first.codeValue != "1";
      } else {
        orderFoodShowPrice = true;
      }
    } catch (e) {
      showToast(e.toNetError());
    }
  }
}
